<?php

/**
 * Algorith:
 * 0. Check if tag in NS; if not -> return null
 * 1. Remove NS
 * 3. Classize
 * 4. Try to load class in package
 * 5. Return object or null
 */
class Cat_Processor_Monkey_TagHandler_FromPackage extends Cat_Processor_Monkey_TagHandlerBase
{
	function __construct( $package )
	{
		$this->setPackage( $package );
	}
	
	private $package;
	
	function setPackage( $package )
	{
		$this->package = $package;
	}
	
	function getPackage()
	{
		return $this->package;
	}
	
	private $ns = '';
	
	function setTagNS( $ns )
	{
		$this->ns = $ns;
	}
	
	function getTagNS()
	{
		return $this->ns;
	}
		
	function getTagObject( $tagName )
	{		
		#0 
		
		$nslen = strlen( $this->ns );
		$tagns = substr( $tagName, 0, $nslen );
		
		if ( $tagns != $this->ns )
		{
			return null;
		}
		
		#1
		
		$tagName = substr( $tagName, $nslen );
				
		#3
		
		$cls = $this->getPackage() . Cat_Strings :: classize( $tagName );

		#4 #5
		
		if ( class_exists( $cls ) )
		{
			return new $cls( $this->getProcessor() );
		}
		
		return null;
	}
}

?>